<template>
  <!-- 项目评估 -->
  <div>
    <div>
      <search-form
        ref="searchBar"
        :search-config="searchConfig"
        :label-width="120"
        @clear="clearSearch"
        @search="handleSearch"
      />
    </div>
    <table-box
      ref="projectEvaluation"
      :selected-arry.sync="tableSelected"
      :table-config="tableConfig"
      :other-filters="otherFilters"
      :other-raw="otherRaw"
      :off-set="-20"
      show-index
      @btnOperate="btnOperate"
    />
    <pro-evaluation-dlg v-if="showDetail" ref="dailyAssessment" :visible.sync="showDetail" :detail-data="activatedData" />
  </div>
</template>

<script>
import ProEvaluationDlg from './component/proEvaluationDlg.vue'
import { getDictByPatchType } from '@/api/dataDict'
export default {
  name: 'ProjectEvaluation',
  components: { ProEvaluationDlg },
  data() {
    return {
      showDetail: false,
      activatedData: {},
      searchConfig: [
        {
          label: '施工单位名称',
          prop: 'unitCode',
          type: 'dialog',
          value: '',
          placeholder: '',
          config: {
            requestMethod: 'post',
            remoteUrl: `${process.env.VUE_APP_BASE_API}/api/v1/configConstUnit/page`,
            paramField: 'keyWord', // 远程搜索参数名
            defaultProps: {
              label: 'unitName',
              value: 'unitCode'
            },
            selectData: []
          },
          dialogConfig: {
            title: '选择表格数据',
            interfacePath: `${process.env.VUE_APP_BASE_API}/api/v1/configConstUnit/page`,
            setting: [{ prop: 'unitCode', title: '编码' }, { prop: 'unitName', title: '名称' }],
            pageFlag: true
          }
        },
        { label: '施工单位负责人', prop: 'principal', type: 'text', value: '', placeholder: '' },
        {
          label: '门店',
          prop: 'shopCode',
          type: 'dialog',
          value: '',
          placeholder: '',
          config: {
            requestMethod: 'post',
            remoteUrl: `/select-service/api/v1/shop/page`,
            paramField: 'keyWord', // 远程搜索参数名
            defaultProps: {
              label: 'name',
              value: 'code'
            },
            selectData: []
          },
          dialogConfig: {
            title: '选择表格数据',
            interfacePath: `/select-service/api/v1/shop/page`,
            setting: [{ prop: 'code', title: '编码' }, { prop: 'name', title: '名称' }],
            pageFlag: true
          }
        },
        {
          label: '评估性质',
          prop: 'scoreNature',
          type: 'select',
          config: {
            selectData: []
          }
        }
      ],
      tableSelected: [],
      otherFilters: [],
      otherRaw: {},
      tableConfig: {
        interfacePath: `${process.env.VUE_APP_BASE_API}/api/v1/constUnitAssessScore/itemScore/page`,
        hideSearchBar: true,
        setting: [
          {
            prop: 'unitCode',
            label: '施工单位编码'
          },
          {
            prop: 'unitName',
            label: '施工单位名称'
          },
          {
            prop: 'principal',
            label: '施工单位负责人'
          },
          {
            prop: 'constCode',
            label: '门店建设项目号'
          },
          {
            prop: 'shopName',
            label: '门店'
          },
          {
            prop: 'decorationTaskCode',
            label: '装修任务'
          },
          {
            prop: 'expectDecorationTime',
            label: '预计进场时间'
          },
          {
            prop: 'actualApproachTime',
            label: '实际进场时间'
          },
          {
            prop: 'expectEndTime',
            label: '预计完工时间'
          },
          {
            prop: 'actualEndTime',
            label: '实际完工时间'
          },
          {
            prop: 'scoreNature',
            label: '评估性质',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'SCORE_NATURE'
            }
          },
          {
            prop: 'actualScore',
            label: '评分'
          }
        ],
        btnList: this.isProduction ? null : [
          {
            buttonName: '查看评估详情',
            optCode: 'check',
            outerFlag: true
          }
        ]
      }
    }
  },
  async created() {
    await this.getDictByPatchTypeAll(['SCORE_NATURE']).then(res => {
      const arr = res.SCORE_NATURE.filter(item => item.dictCode !== 'DAILY')
      const scoreNatureList = arr.map(item => {
        const obj = { label: item.dictName, value: item.dictCode }
        return obj
      })
      this.$set(this.searchConfig[3].config, 'selectData', scoreNatureList)
    })
  },
  activated() {},
  methods: {
    // 获取数据字典
    async getDictByPatchTypeAll(data) {
      const obj = await getDictByPatchType(data)
        .then(res => {
          return res
        })
      return obj
    },
    btnOperate(flag) {
      switch (flag) {
        case 'check':
          if (!this.singleJudge(this.tableSelected, '查看评估详情', false)) {
            return
          }
          this.checkDetail(this.tableSelected[0])
          break
        default:
          break
      }
    },
    handleSearch(data) {
      if (data && data.filtersRaw) {
        data.filtersRaw.forEach(item => {
          if (item.property === 'shopCode') {
            this.otherRaw = { 'shopCode': item.value }
          }
        })
        const arr = data.filtersRaw.filter(item => item.property !== 'shopCode')
        this.otherFilters = [...arr]
        this.$nextTick(() => {
          this.$refs.projectEvaluation.initTableData()
        })
      }
    },
    clearSearch() {
      this.otherFilters = []
      this.otherRaw = {}
    },
    checkDetail(row) {
      this.activatedData.flag = 'proEvaluation'
      this.activatedData.data = row
      this.showDetail = true
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
